package liumengbaio.lolzhangyoubao.Activity.Activity;

import android.content.Intent;
import android.os.Bundle;
import android.support.annotation.Nullable;
import android.support.v7.app.AppCompatActivity;
import android.view.MotionEvent;
import android.view.View;
import android.view.ViewGroup;
import android.webkit.WebSettings;
import android.webkit.WebView;
import android.widget.ImageView;
import android.widget.PopupWindow;

import liumengbaio.lolzhangyoubao.Activity.utils.GoodView;
import liumengbaio.lolzhangyoubao.R;

/**
 * Created by lanouhn on 16/9/7.
 */
public class HeroVideoDetailsActivity extends AppCompatActivity {
    private WebView webView;
    private String url, hero_url;
    private ImageView back, more, good, goodChecked, bad, badChecked;
    private PopupWindow mheroPopupWindow;
    private GoodView mheroGoodView;

    @Override
    protected void onCreate(@Nullable Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_herovideodetails);
        mheroGoodView=new GoodView(this);
        initView();
        initData();
        initEvent();
    }
    private void initView() {
        webView= (WebView) findViewById(R.id.video_hero_wb);
        back= (ImageView) findViewById(R.id.video_hero_Back);
        more= (ImageView) findViewById(R.id.video_hero_More);
        good= (ImageView) findViewById(R.id.herovideo_good);
        goodChecked= (ImageView) findViewById(R.id.herovideo_goodChecked);
        bad= (ImageView) findViewById(R.id.herovideo_bad);
        badChecked= (ImageView) findViewById(R.id.herovideo_badChecked);
    }

    private void initData() {
        WebSettings mWebSettings = webView.getSettings();
        mWebSettings.setJavaScriptEnabled(true);
        Intent intent = getIntent();
        hero_url=intent.getStringExtra("hero_url");
        webView.loadUrl(hero_url);
    }

    private void initEvent() {
        back.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                finish();
            }
        });
        webView.setOnTouchListener(new View.OnTouchListener() {
            @Override
            public boolean onTouch(View v, MotionEvent event) {
                WebSettings heroWebSettings =webView.getSettings();
                heroWebSettings.setJavaScriptEnabled(true);
                Intent intent =getIntent();
                url=intent.getStringExtra("video_url");
                webView.loadUrl(url);
                return false;
            }

        });

        more.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                final View view = getLayoutInflater().inflate(R.layout.video_popwindow, null);
                mheroPopupWindow = new PopupWindow(view, ViewGroup.LayoutParams.WRAP_CONTENT, ViewGroup.LayoutParams.WRAP_CONTENT, true);
                mheroPopupWindow.showAsDropDown(more);
                view.setOnTouchListener(new View.OnTouchListener() {
                    @Override
                    public boolean onTouch(View v, MotionEvent event) {
                        if (mheroPopupWindow != null && mheroPopupWindow.isShowing()) {
                            mheroPopupWindow.dismiss();
                            mheroPopupWindow = null;
                        }
                        return false;
                    }
                });

            }
        });

        good.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                good.setVisibility(View.INVISIBLE);
                goodChecked.setVisibility(View.VISIBLE);
                mheroGoodView.setImage(getResources().getDrawable(R.mipmap.video_third_goodup));
                mheroGoodView.show(v);
                bad.setEnabled(false);
            }
        });
        goodChecked.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                good.setVisibility(View.VISIBLE);
                goodChecked.setVisibility(View.INVISIBLE);
                bad.setEnabled(true);
            }
        });
        bad.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                bad.setVisibility(View.INVISIBLE);
                badChecked.setVisibility(View.VISIBLE);
                good.setEnabled(false);
            }
        });
        badChecked.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                bad.setVisibility(View.VISIBLE);
                badChecked.setVisibility(View.INVISIBLE);
                good.setEnabled(true);
            }
        });
    }

}
